package io.renren.modules.device.dao;

import io.renren.modules.device.entity.TAlarmType;
import io.renren.modules.device.entity.TDeviceCategory;
import io.renren.modules.device.entity.TDeviceEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.device.entity.vo.DeviceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 设备表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-03-29 11:51:23
 */
@Mapper
public interface TDeviceDao extends BaseMapper<TDeviceEntity> {

//    @Select("SELECT td.*, tu.username as creatorName FROM t_device td LEFT JOIN tb_user tu ON td.creator = tu.user_id WHERE td.`status` = 1")
//    @Select("SELECT td.*, su.username as creatorName FROM t_device td LEFT JOIN sys_user su ON td.creator = su.user_id ")
    List<DeviceVO> queryDevices(@Param("categoryId") String categoryId);

//    @Select("SELECT td.*, su.username as creatorName FROM t_device td LEFT JOIN sys_user su ON td.creator = su.user_id WHERE td.`name` LIKE #{key} OR td.`code` LIKE #{key}")
    List<DeviceVO> queryDevicesByKeySearch(@Param("key") String key, @Param("categoryId") String categoryId);

    DeviceVO getDeviceInfoById(@Param("key") String key);

    @Select("SELECT * FROM t_device WHERE code = #{code}")
    TDeviceEntity getDeviceInfoByCode(@Param("code") String code);

    @Select("SELECT * FROM t_category WHERE 1")
    List<TDeviceCategory> listCategory();

    @Select("SELECT * FROM t_category WHERE id = #{cateId}")
    TDeviceCategory categoryInfo(@Param("cateId") String cateId);

    @Select("SELECT * FROM t_alarm_type WHERE 1")
    List<TAlarmType> listAlarmTypes();
}
